import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store/index'
import Components from "./components"
Vue.config.productionTip = false

Vue.use(Components)

/*
* 判断登陆权限
* */

const notLoginPages = ['/login']
router.beforeEach((to, from, next) => {
  let token = localStorage.getItem('token')// 是否登陆需要token来判断
  if (notLoginPages.indexOf(to.path) < 0) {// 以下是需要登陆的页面
    if (token) {
      /*
      * 如果登陆过进行下一级路由
      * */
      next()
    } else {
      if (to.path === '/login') {
        next()
      } else {
        next('/login')
      }
    }
  } else {// 以下是不需要登陆的页面
    next()
  }
})


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
